package com.example.partiu;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class CadastrarMateriaActivity extends Activity {
	BancoDeDados dbHelper = null;
	 SQLiteDatabase db = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_cadastrar_materia);
		try{
			dbHelper = new BancoDeDados(getApplicationContext());
		}catch(Exception ex){
			new AlertDialog.Builder(this).setMessage(ex.getMessage()).setPositiveButton("OK", null).show();
		}
	}

	//Salva as entradas de dados no Banco de Dados
		public void salvar(View view){
			try{
				EditText edit = (EditText) findViewById(R.id.editText1);
				EditText edit2 = (EditText) findViewById(R.id.editText2);
				EditText edit3 = (EditText) findViewById(R.id.editText3);
				EditText edit4 = (EditText) findViewById(R.id.editText4);
				String nome = edit.getText().toString();
				String diasemana = edit2.getText().toString();
				String horario = edit3.getText().toString();
				String fpermitidas = edit4.getText().toString();
				db = dbHelper.getWritableDatabase();
				db.execSQL("INSERT INTO MATERIA(NOME, DIASEMANA, HORARIO, FPERMITIDAS) " +
						"VALUES('" + nome + "', '" + diasemana + "', '" + horario + "', '" + fpermitidas + "')");
				db.close();
				dbHelper.close();
				edit.setText("");
				edit2.setText("");
				edit3.setText("");
				edit4.setText("");
				Intent intent = new Intent(this, ListaActivity.class);
				startActivity(intent);
				
		}catch(Exception ex){
			new AlertDialog.Builder(this).setMessage(ex.getMessage()).setPositiveButton("OK", null).show();
		}
		}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.cadastrar_materia, menu);
		return true;
	}

}
